<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<script type="text/javascript">
//<![CDATA[
    i=0;
    var recipCount = 0;
    var maxRecip   = <?php echo $this->getRecipientsLimit() ?>;
    function remove_recipient(i){
        $('recipients_name'+i).up(2).remove();
        recipCount--;
        if(recipCount<maxRecip && maxRecip != 0) {
            $('add_recipient_button').show();
            $('max_recipient_message').hide();
        }
        return false;
    }

    function add_recipient(email, name)
    {
        if (typeof email == 'undefined') email = '';
        if (typeof name == 'undefined') name = '';
        ul = $('recipients_options');
        var li_mail = Element.extend(document.createElement("li"));
        li_mail.addClassName('fields');

        if (i!=0) {
            li_mail.innerHTML = '<p class="btn-remove"><a href="delete_email" onclick="remove_recipient('+i+'); return false" class="btn-remove"><img src="<?php echo $this->getSkinUrl('images/btn_remove.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Remove Email'), true) ?>" /><\/a><\/p>'
            li_mail.addClassName('add-row');
        }
        li_mail.innerHTML += '<div class="field"><label for="recipients_name'+i+'" class="required"><em>*<\/em> <?php echo Mage::helper('core')->jsQuoteEscape($this->__('Name:')) ?><\/label><div class="input-box"><input name="recipients['+i+'][name]" type="text" value="'+name+'" class="input-text required-entry" id="recipients_name'+i+'" /><\/div><\/div>';
        li_mail.innerHTML += '<div class="field"><label for="recipients_email'+i+'" class="required"><em>*<\/em> <?php echo Mage::helper('core')->jsQuoteEscape($this->__('Email Address:')) ?><\/label><div class="input-box"><input name="recipients['+i+'][email]" value="'+email+'" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address'), true) ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" /><\/div><\/div>';
        i++;
        recipCount++;
        if(recipCount>=maxRecip && maxRecip != 0) {
            $('add_recipient_button').hide();
            $('max_recipient_message').show();
        }

        ul.appendChild(li_mail);
    }
//]]>
</script>

<div class="page-title">
    <h1><?php echo $this->getFormHeader() ?></h1>
</div>
<?php echo $this->getMessagesBlock()->toHtml(); ?>
<form action="<?php echo $this->getSendUrl() ?>" method="post" id="giftregistry_sharing_form">
    <div class="fieldset">
        <?php echo $this->getBlockHtml('formkey')?>
        <h2 class="legend"><?php echo $this->__('Sender:') ?></h2>
        <ul class="form-list" id="sender_options">
            <li class="fields">
                <div class="field">
                    <label for="sender_name" class="required"><em>*</em><?php echo $this->__('Name:') ?></label>
                    <div class="input-box">
                        <input name="sender_name" value="<?php if ($this->getFormData('sender_name')): ?><?php echo $this->getFormData('sender_name') ?><?php else:?><?php echo $this->getCustomerName() ?><?php endif;?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Name')) ?>" id="sender_name" type="text" class="input-text required-entry" />
                    </div>
                </div>
                <div class="field">
                   <label for="sender_email" class="required"><em>*</em><?php echo $this->__('Email:') ?></label>
                    <div class="input-box">
                       <input name="sender_email" value="<?php if ($this->getFormData('sender_email')): ?><?php echo $this->getFormData('sender_email'); ?><?php else:?><?php echo $this->getCustomerEmail() ?><?php endif;?>" id="sender_email" type="text" class="input-text required-entry validate-email" />
                    </div>
                </div>
            </li>
            <li>
                <label for="sender_message" class="required"><em>*</em><?php echo $this->__('Message:') ?></label>
                <div class="input-box">
                    <textarea name="sender_message" class="input-text required-entry" id="sender_message" cols="3" rows="3" style="height:100px;"><?php echo $this->getFormData('sender_message'); ?></textarea>
                </div>
            </li>
        </ul>
    </div>
    <div class="fieldset">
        <h2 class="legend"><?php echo $this->__('Recipient:') ?></h2>
        <ul class="form-list" id="recipients_options" >
            <li class="no-display">&nbsp;</li>
        </ul>
    </div>
    <div class="buttons-set form-buttons">
        <p class="back-link">
            <span id="max_recipient_message" style="display:none;">
                <?php if ($this->getRecipientsLimit()): ?>
                    <?php echo $this->__('Maximum %d email addresses allowed.', $this->getRecipientsLimit()) ?>
                <?php endif; ?>
            </span>&nbsp;
        </p>
        <button type="submit" class="button"><span><span><?php echo $this->__('Share Gift Registry') ?></span></span></button>
        <?php if ($this->getRecipientsLimit()): ?>
            <button type="button" id="add_recipient_button" onclick="add_recipient();" class="button"><span><span><?php echo $this->__('Add Recipient') ?></span></span></button>
        <?php endif; ?>
    </div>
    <p class="required"><?php echo $this->__('* Required Fields') ?></p>
</form>
<div class="buttons-set">
    <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
</div>

<script type="text/javascript">
//<![CDATA[
    var giftRegistrySharingForm = new VarienForm('giftregistry_sharing_form');

    <?php if ($this->getFormData('recipients')): ?>
        <?php foreach($this->getFormData('recipients') as $recipient): ?>
           add_recipient('<?php echo $recipient[1] ?>','<?php echo $recipient[0] ?>');
        <?php endforeach;?>
    <?php else: ?>
        add_recipient();
    <?php endif; ?>
//]]>
</script>

